

package org.come.login;

import com.updateNew.MyIsif;
import org.apache.commons.lang.StringUtils;
import org.come.bean.LoginInfo;
import org.come.bean.LoginRoleInfo;
import org.come.bean.PathPoint;
import org.come.test.Main;
import org.come.until.GsonUtil;
import org.come.until.Music;
import org.come.until.Util;

import javax.swing.*;
import java.awt.*;

public class LoginFrame extends JFrame {
    private LoginJpanel loginJpanel;
    private LoginInfo loginInfo;
    private LoginRoleInfo roleInfo;

    public LoginFrame() {
        Music.addbeijing("0001-615041B0.mp3");
//		Music.addbeijing("0002-63BC3C5F.mp3");
        String userInfoStr = Util.readUserInfo();
        if (StringUtils.isNotBlank(userInfoStr)) {
            try {
                loginInfo = GsonUtil.getGsonUtil().getgson().fromJson(userInfoStr, LoginInfo.class);
            } catch (Exception e) {
            }
        }
        if (loginInfo == null) {
            loginInfo = new LoginInfo();
        }
        this.loginJpanel = new LoginJpanel(loginInfo);
//		setAlwaysOnTop(true);
        //多开变单开
        String a = MyIsif.ifs;
        this.setContentPane(this.loginJpanel);
        //单开变多开
        if (a.equals("D")) {
            //多开变单开
            this.setTitle("大话西游Ⅱ经典版");
        } else {
            setUndecorated(true);
            this.setTitle("大话西游Ⅱ经典版" + Main.index + Main.name.toString());
            setLocation(5, 54);
        }
        this.setResizable(false);
        Toolkit tool = this.getToolkit();
        Image myimage = tool.getImage("img/icon/ico.png");
        this.setIconImage(myimage);
        this.pack();
        this.setVisible(true);
        if (a.equals("D")) {
            this.setLocationRelativeTo(null);
        }
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        //多开变单开

//        if (!a.equals("D"))
//            setLocation(5, 55);
//        else
//            setLocation(410, 80);//选取窗口xy坐标
    }

    public LoginJpanel getLoginJpanel() {
        return this.loginJpanel;
    }

    public void setLoginJpanel(LoginJpanel loginJpanel) {
        this.loginJpanel = loginJpanel;
    }

    public PathPoint mousepath() {
        Point p = MouseInfo.getPointerInfo().getLocation();
        Point p1 = this.getLocation();
        Main.pathPoint.setX((int) (p.getX() - p1.getX() - 4));
        Main.pathPoint.setY((int) (p.getY() - p1.getY() - 26));
        return Main.pathPoint;
    }

    public void setRoleInfo(LoginRoleInfo roleInfo) {
        this.roleInfo = roleInfo;
    }

    public LoginRoleInfo getRoleInfo() {
        if (roleInfo == null) {
            roleInfo = new LoginRoleInfo();
        }
        return roleInfo;
    }

    public LoginInfo getLoginInfo() {
        return loginInfo;
    }
}
